﻿using System.Web.Mvc;
using MvcTemplates.Model;

namespace MvcTemplates.Client.Models
{
    public class ViewModelForDocumentation
    {
        [HtmlAttributes( new[] {"class"}, new[] {"random_class"} )]   
        [HelpMessage("You can completely customize html attributes by using the HtmlAttributes Attribute")]
        public string TextBox { get; set; }

        [FieldContainer(typeof(CustomFieldsetTagBuilder))]
        [Label(DoNotRender = true)] //the fieldset tag builder will add the label into the legend
        [HelpMessage("You can control field and label containers by using the FieldContainer or LabelContainer Attribute")]
        public string TextBoxWithCustomFieldContainer { get; set; }

        public class CustomFieldsetTagBuilder : TagBuilder
        {
            public CustomFieldsetTagBuilder() : base( "fieldset" )
            {
                var legend = new TagBuilder( "legend" );
                legend.SetInnerText( "Text Box with Custom Field Container!" );
                legend.Attributes.Add( "style", "padding-top:20px;" );
                this.InnerHtml = legend.ToString();
            }
        }

        [AutoComplete( "Autocomplete", "Home", Delay = 0)]
        [HelpMessage("Start typing the word Link")]
        public string AutoComplete { get; set; }
        
        [HelpMessage("A static Help Message")]        
        public string HelpMessage { get; set; }

        [HelpMessage("A custom wrapper for this help message", TagBuilderType = typeof(CustomHelpMessageWrapper) )]
        public string HelpMessageWithCustomWrapper { get; set; }
        
        public class CustomHelpMessageWrapper : TagBuilder
        {
            public CustomHelpMessageWrapper() : base( "div" )
            {
                this.Attributes["id"] = "helpMessageWithCustomWrapperId";
                this.AddCssClass( "some_class" );
                this.InnerHtml = "it's custom!";
            }
        }

        /// <summary>
        /// DropDown has 2 properties:
        /// public object Value { get; set; }
        /// public IEnumerable<SelectListItem> Options { get; set; }
        /// </summary>
        public DropDown DropDown { get; set; }

        [DropDown("SelectListItemsViewDataKey")] //uses ViewData["SelectListItemsViewDataKey"] for the Options of the DropDown
        public string DropDownOptionsFromViewData { get; set; }

        /// <summary>
        /// CheckBoxList has 2 properties:
        /// public object[] SelectedOptions { get; set; }
        /// public IEnumerable<SelectListItem> Options { get; set; }
        /// </summary>
        public CheckBoxList CheckBoxList { get; set; }

        /// <summary>
        /// RadioButtonList has 2 properties:
        /// public object Value { get; set; }
        /// public IEnumerable<SelectListItem> Options { get; set; }
        /// </summary>
        public RadioButtonList RadioButtonList { get; set; }

        [DisplayTemplate] //calls Html.Display( property ) instead of Html.Editor( property )
        public string DisplayNoInput { get; set; }
        
        [DoNotRender] //same as ScaffoldColumn(false) but much more intuitive
        public string IgnoreThisField { get; set; }

        [Label( RenderAfterField = true, PutInFieldContainer = true, Text = "Check box with Label Rendered after the Field" )]
        public bool CheckBoxWithLabelOnRight { get; set; }

        [LabelAfterField("two labels")]
        [HelpMessage("This checkbox shows that you can have an additional label if you use the LabelAfterField Attribute")]
        public bool AnotherCheckBox { get; set; }

        [Label(Text = "Some Label")]
        public string TextBox2 { get; set; }

        public ViewModelForDocumentation()
        {
            TextBox = "hi i'm a text box with a random_class css class added";            
            DisplayNoInput = "I called Html.DisplayFor() instead of EditorFor";
            
            DropDown = new DropDown
                           {
                               Value = "using a model",
                               Options = new SelectList( new[] {"thing3", "thing4", "using a model"}, "using a model" )
                           };
            
            CheckBoxList = new CheckBoxList
                               {
                                   SelectedOptions = new[]{ "thing3", "thing4" },
                                   Options = new SelectList( new[]{ "thing1", "thing2", "thing3", "thing4" } )
                               };

            RadioButtonList = new RadioButtonList
                                  {
                                      Value = "using a model",
                                      Options = new SelectList( new[] {"thing3", "thing4", "using a model"}, "using a model" )
                                  };            
        }
    }    
}